package com.letv.core.utils;

import android.util.Log;

import com.letv.core.config.LetvConfig;

/**
 * 打印log帮助类
 * 
 * @author zhuqiao
 * 
 */
public class LogInfo {
    private final static boolean isDebug = LetvConfig.isDebug();
    private static String TAG = "haitian";
    private static String TAG_STATISTICS = "statistics";
    private final static int DEBUG_LEVEL = 4;
    private static final String TAG_CONTENT_PRINT = "%s:%s.%s:%d";

    public static void log(String msg) {
        log(TAG, msg);
    }

    /**
     * 统计信息打印
     * 
     */
    public static void LogStatistics(String msg) {
        log(TAG_STATISTICS, msg);
    }

    public static void log(String tag, String msg) {
        if (isDebug) {
            switch (DEBUG_LEVEL) {
                case 0:
                    Log.i(tag, msg);
                    break;
                case 1:
                    Log.d(tag, msg);
                    break;
                case 2:
                    Log.v(tag, msg);
                    break;
                case 3:
                    Log.w(tag, msg);
                    break;
                case 4:
                    Log.e(tag, msg);
                    break;
                default:
                    Log.i(tag, msg);
                    break;
            }
        }
    }

    /**
     * 打印trace
     * 
     * @param tag
     * @param msg
     */
    public static void trace(String tag) {
        if (isDebug) {
            Log.d(tag, getContent(getCurrentStackTraceElement(), tag));
        }
    }

    private static StackTraceElement getCurrentStackTraceElement() {
        return Thread.currentThread().getStackTrace()[4];
    }

    private static String getContent(StackTraceElement trace, String tag) {
        return String
                .format(TAG_CONTENT_PRINT, tag, trace.getClassName(), trace.getMethodName(), trace.getLineNumber());
    }
}
